package com.feiyue.learning.base;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 日期使用
 * @author  feiyue
 * @date  2020/4/12
 */
public final class CalendarDemo {

    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(2019, Calendar.DECEMBER, 31);
        calendar.set(Calendar.HOUR_OF_DAY, 13);
        Date date = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd hh:mm");

        // 2020-12-31 01:34
        System.out.println(sdf.format(date));

        // Calendar.HOUR - 12 小时制
        calendar.set(Calendar.HOUR, 11);
        System.out.println(calendar.getTime());

        // Calendar.HOUR_OF_DAY - 24 小时制
        calendar.set(Calendar.HOUR_OF_DAY, 13);
        System.out.println(calendar.getTime());
    }

    public void print() {
        List list = new ArrayList<>();
        for (int i = 0, len = list.size(); i < len; i++) {
            System.out.print(i);
        }
    }
}
